package cn.com.api.mapper.base;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;

import cn.com.api.entity.U_label;

//DAO
public interface U_labelMapperBase {

	// 根据id查看
	@Select("SELECT * FROM u_label  WHERE id = #{id}")
	public U_label findU_labelById(Integer id);

	// 查看数据集
	@Select("SELECT a.*,(select b.label_name from u_label b where b.id = a.parent_id) parent_name FROM U_label a ORDER BY a.TYPE asc,a.PARENT_ID ASC,a.sort asc")
	public List<U_label> findU_labels();

	// 添加
	@Insert("INSERT INTO u_label (label_name, sort, parent_id, create_time,type) VALUES (#{label_name}, #{sort}, #{parent_id}, #{create_time}, #{type})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	public int insertU_label(U_label u_label);

	// 修改
	@Update("UPDATE u_label SET label_name = #{label_name}, sort = #{sort}, parent_id = #{parent_id}, create_time = #{create_time} WHERE id = #{id}")
	public int updateU_label(U_label u_label);

	// 删除
	@Delete("DELETE FROM u_label  WHERE id = #{id}")
	public int deleteU_label(Integer id);

	// Foreign keys revelant

	// region Indexs revelant

	// 获取根据parent_id
	@Select("SELECT id, label_name, sort, parent_id, create_time FROM u_label  WHERE parent_id = #{parent_id}")
	public List<U_label> findU_labelsByParent_id(String parent_id);

}
